package day07;

import java.util.Random;
import java.util.Scanner;

/**
 * 猜数字小游戏
 * 训练目标: while(true)自造死循环
 */
public class Guessing {
    public static void main(String[] args) {
      /*  Random r = new Random();
        Scanner sc = new Scanner(System.in);
        int num = r.nextInt(100) + 1;
        int guess;
        while (true) {
            System.out.println("请猜");
            guess = sc.nextInt();
            if (guess > num) {
                System.out.println("大了");
            } else if (guess < num) {
                System.out.println("小了");
            } else {
                System.out.println("猜对了!");
                break;
            }
        }*/
        Random r = new Random();
        Scanner sc = new Scanner(System.in);
        int num = r.nextInt(100) + 1;
        System.out.println(num);
        int guess;
        while (true) {
            System.out.println("请猜");
            guess = sc.nextInt();
            guessNum(guess, num);
        }
    }

    public static void guessNum(int guess, int num) {
        if (guess > num) {
            System.out.println("猜大了");
        } else if (guess < num) {
            System.out.println("猜小了");
        } else {
            System.out.println("猜对了!!");
            System.exit(0);
        }

    }
}
